package com.csx.governance.traffic.adm.model.common;

import lombok.Getter;

@Getter
public class Result<T> {

    private static final int SUCCESS_CODE = 200;

    private static final int ERROR_CODE = 400;

    private static final String SUCCESS_MESSAGE = "success";

    private static final String ERROR_MESSAGE = "error";

    private int code;

    private String message;

    private T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        return success(data, SUCCESS_MESSAGE);
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<>(SUCCESS_CODE, message, data);
    }

    public static <T> Result<T> error() {
        return error(null);
    }

    public static <T> Result<T> error(String message) {
        return success(ERROR_CODE, SUCCESS_MESSAGE);
    }

    public static <T> Result<T> success(int code, String message) {
        return new Result<>(code, message, null);
    }

}
